package com.gdpu.controller;

import com.gdpu.api.CommonPage;
import com.gdpu.api.CommonResult;
import com.gdpu.service.PortalPmsGoodsService;
import com.gdpu.vo.PmsGoodDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @Author:weiming
 * @Date:2021/6/11
 */
@Api(tags = "客户端商品")
@RestController
@RequestMapping("/goods")
public class PortalPmsGoodsController {

    @Autowired
    private PortalPmsGoodsService pmsGoodsService;


    @ApiOperation("根据分类id获取商品列表")
    @GetMapping("/list")
    public CommonResult list(@RequestParam(name = "categoryId") Integer categoryId,
                             @RequestParam(name = "pageNum",defaultValue = "0") Integer pageNum,
                             @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize){
        CommonPage commonPage = pmsGoodsService.listByCategoryId(categoryId, pageNum, pageSize);
        HashMap<String, Object> map = new HashMap<>(1);
        map.put("goodList",commonPage);
        if (commonPage!=null){
            return  CommonResult.success(map);
        }
        return CommonResult.failed();
    }


    @ApiOperation("获取商品详情")
    @GetMapping("/{goodId}")
    public CommonResult detail(@PathVariable(name = "goodId") Integer goodId){
        PmsGoodDetailVo pmsGoodDetailVo = pmsGoodsService.detail(goodId);
        HashMap<String, Object> map = new HashMap<>(1);
        map.put("goodDetail",pmsGoodDetailVo);
        if (pmsGoodDetailVo != null) {
            return CommonResult.success(map);
        }
        return CommonResult.failed();
    }




}
